package com.hxzy.service.impl;

import com.hxzy.dto.CellinfoDTO;
import com.hxzy.entity.Cellinfo;
import com.hxzy.util.MybatisUtil;
import com.hxzy.mapper.cellinfoMapper;
import com.hxzy.service.cellinfoService;
import org.apache.ibatis.session.SqlSession;

import java.util.ArrayList;
import java.util.List;


/**
 * @Description:
 * @Author: YangYong
 * @Date: 2022/3/8 15:47
 */
public class cellinfoSerxiceIpml implements cellinfoService {
    @Override
    public int insert(Cellinfo cellinfo) {
        int count=0;
        try (SqlSession sqlSession = MybatisUtil.getSqlSessionFactory().openSession()) {
            cellinfoMapper mapper = sqlSession.getMapper(cellinfoMapper.class);
            count = mapper.insert(cellinfo);
            sqlSession.commit();
        }
        return count;
    }

    @Override
    public List<Cellinfo> search(CellinfoDTO village_name) {
        List<Cellinfo> arr = new ArrayList<>();
        try (SqlSession sqlSession = MybatisUtil.getSqlSessionFactory().openSession()) {
            cellinfoMapper mapper = sqlSession.getMapper(cellinfoMapper.class);
            arr = mapper.search(village_name);
        }
        return arr;
    }


    @Override
    public int delete(String id) {
        int count =0;
        try(SqlSession sqlSession=MybatisUtil.getSqlSessionFactory().openSession()){
            cellinfoMapper mapper=sqlSession.getMapper(cellinfoMapper.class);
            count = mapper.delete(id);
            sqlSession.commit();
        }
        return count;
    }

    @Override
    public int update(Cellinfo id) {
        int count =0;
        try(SqlSession sqlSession=MybatisUtil.getSqlSessionFactory().openSession()){
            cellinfoMapper mapper=sqlSession.getMapper(cellinfoMapper.class);
            count = mapper.update(id);
            sqlSession.commit();
        }
        return count;
    }

    @Override
    public Cellinfo findOne(String id) {
        Cellinfo cellinfo=null;
        try (SqlSession sqlSession=MybatisUtil.getSqlSessionFactory().openSession()){
            cellinfoMapper mapper = sqlSession.getMapper(cellinfoMapper.class);
            cellinfo=mapper.findOne(id);
        }
        return cellinfo;
    }

    @Override
    public List<Cellinfo> searchall(CellinfoDTO cellinfoDTO) {
        List<Cellinfo>list=new ArrayList<>();
        try (SqlSession sqlSession = MybatisUtil.getSqlSessionFactory().openSession()) {
            cellinfoMapper mapper = sqlSession.getMapper(cellinfoMapper.class);
            list = mapper.searchall(cellinfoDTO);
        }
        return list;
    }
}
